import request from '@/utils/request';
import { ResponseData } from '../typing';

/**
 * 上传文件
 * @param {string} file
 * @returns
 */
export function uploadFile(
    file: object,
    config: {
        // controller: AbortController;
        onUploadProgress?: (progressEvent: any) => void;
    },
): Promise<ResponseData<boolean>> {
    return request.post(`/file/upload`, file, {
        ...config,
        headers: {
            'Content-Type': 'multipart/form-data',
        },
    });
}

/**
 * 下载文件
 * @returns
 */
export function getFileContent(): Promise<ResponseData<boolean>> {
    return request.get(`/file/download`, {
        responseType: 'blob',
    });
}

/**
 * 删除文件
 * @param {string} filename
 * @returns
 */
export function deleteFile(filename: string): Promise<ResponseData<boolean>> {
    return request.delete(`/file/delete?filename=${filename}`);
}
